package com.liqi.web.controller.device;

import com.liqi.common.core.domain.PageData;
import com.liqi.common.core.domain.PageParam;
import com.liqi.common.core.domain.R;
import com.liqi.dev.domain.DvPlugin;
import com.liqi.dev.domain.DvPluginVersion;
import com.liqi.dev.pojo.DvPluginMallReq;
import com.liqi.dev.pojo.DvPluginPageReq;
import com.liqi.dev.pojo.DvPluginUpgradeReq;
import com.liqi.web.controller.common.minio.MinIoService;
import com.liqi.web.service.device.DvPluginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author tianye
 * @date 2023-04-03
 */
@Api(tags = "插件管理")
@RestController
@RequestMapping("/dvPlugin")
public class DvPluginController {

    @Autowired
    private DvPluginService dvPluginService;

    @Autowired
    private MinIoService minIoService;

    @ApiOperation("分页")
    @PostMapping("/page")
    public R<PageData<DvPlugin>> page(@RequestBody PageParam<DvPluginPageReq> pageParam) {
        return dvPluginService.page(pageParam);
    }

    @ApiOperation("版本列表")
    @GetMapping("/versionList/{pluginCode}")
    public R<List<DvPluginVersion>> versionList(@PathVariable("pluginCode") String pluginCode) {
        return R.ok(dvPluginService.versionList(pluginCode));
    }

    @ApiOperation("版本升级")
    @PostMapping("/upgrade")
    public R upgrade(@RequestBody DvPluginUpgradeReq dvPlugin) {
        return dvPluginService.upgrade(dvPlugin);
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public R add(@RequestBody DvPlugin dvPlugin) {
        return dvPluginService.add(dvPlugin);
    }

//    @ApiOperation("修改")
//    @PostMapping("/modify")
//    public R modify(@RequestBody DvPlugin dvPlugin) {
//        return dvPluginService.modify(dvPlugin);
//    }

    @ApiOperation("删除")
    @DeleteMapping("/delete/{pluginId}")
    public R delete(@PathVariable("pluginId") Integer pluginId) {
        return dvPluginService.delete(pluginId);
    }

    @ApiOperation("client-我的插件")
    @PostMapping("/myPlugin")
    public R<PageData<DvPlugin>> myPlugin(@RequestBody PageParam<List<Integer>> pageParam) {
        return dvPluginService.myPlugin(pageParam);
    }

    @ApiOperation("client-插件市场")
    @PostMapping("/mall")
    public R<PageData<DvPlugin>> mall(@RequestBody PageParam<DvPluginMallReq> pageParam) {
        return dvPluginService.mall(pageParam);
    }

    @ApiOperation("client-文件下载")
    @GetMapping("/download")
    public void download(String fileName, HttpServletResponse response) {
        minIoService.download(fileName, response);
    }

}
